package com.currency.simulation;

public class MovingAverageTest implements NewEntryHandler
{
	private int numEntries;
	
	public static void main(String args[])
	{
		MovingAverageTest test = new MovingAverageTest();
		test.execute();
	}
	
	public MovingAverageTest()
	{
		numEntries = 0;
	}
	
	public void execute()
	{
		Generator g = Generator.getInstance();
		g.startGenerating(this);
		
		for(int i = 0; i < 20; i++)
		{
			try
			{
				printMessage("Still working - " + (i + 1));
				Thread.sleep(500);
			}
			catch(InterruptedException e)
			{
				e.printStackTrace();
			}
		}
	}
	
	public synchronized void printMessage(String msg)
	{
		System.out.println(msg);
	}

	@Override
    public void handleNewEntry(int newVal)
	{
		numEntries++;
		printMessage("Callback - new entry added " + newVal + " (" + numEntries + ")");
    }
}
